using IdentityServer4.Configuration;
using Microsoft.AspNetCore.Authentication.Cookies;
using RuoVea.ExApp;
using RuoVea.ExConfig;
using RuoVea.ExUtil;
using RuoVea.Identity;
using RuoVea.Identity.Server;

var builder = WebApplication.CreateBuilder(args).Inject();

// Add services to the container.
var service = builder.Services;
service.AddControllersWithViews();

//var   ty=Appsettings.GetAppSettings<List<AuthServerInfo>>("AuthServerInfo");
//var   ty=Appsettings.GetConfig<AuthServerInfos> ("AuthServerInfoss");
//service.AddAuthentication(CookieAuthenticationDefaults.AuthenticationScheme).AddCookie(op => {
//    op.LoginPath = "/auth/login";

//});

builder.Services.AddIdentityServer(
    new List<AuthServerInfo> {
        new AuthServerInfo{
            ClientId= "B3nWICDfAhuD0Fvk",
            ClientSecrets= "8Sba38fKlqlQ41buLrAqsXgSijjAG2Cy",
            RedirectUris=new List<string>{ "https://www.ruovea.com/gantt/callback", "https://www.ruovea.com/fin/callback" },
            ResponseType= "Jwt"
        }
    }, "JWTSetting", "IdentityOptions");

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

app.UseCookiePolicy();
//app.UseSession();


app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthentication(); //Added
app.AddServerEndpoint();

app.UseAuthorization();


app.MapControllerRoute(
    name: "default",
    pattern: "{controller=Home}/{action=Index}/{id?}");

app.Run();
